package com.societyGames.precedenceExercises
{
	public class ModuloExpression implements INumberExpression
	{
		private var _left:INumberExpression;
		private var _right:INumberExpression;
		
		public function ModuloExpression(xml:XML)
		{
			if (!("left" in xml) || !("right" in xml))
			{
				throw new ArgumentError("ModuloExpression requires left and right children.");
			}
			this._left = Parser.parse(xml.left.children()[0]);
			this._right = Parser.parse(xml.right.children()[0]);
		}
		
		public function toString():String
		{
			return "modulo(" + Object(this._left).toString() + ", " + Object(this._right).toString() + ")";
		}
		
		//INumberExpression-->
		public function evaluate():Number
		{
			return this._left.evaluate() % this._right.evaluate();	
		}
		//<--INumberExpression
	}
}